package jencli

import (
	"GoMaestro/internal/conf"
	"context"
	"github.com/bndr/gojenkins"
	"log/slog"
	"os"
)

func Init() {
	var err error
	ctx := context.Background()
	// 这里发现使用token进行请求会提高响应效率，减少花费的时间
	conf.JenClient = gojenkins.CreateJenkins(nil, conf.C.Jenkins.Address, conf.C.Jenkins.Username, conf.C.Jenkins.Token)
	_, err = conf.JenClient.Init(ctx)
	if err != nil {
		slog.Error("init jenkins error", slog.Any("error", err))
		os.Exit(5)
	}
	slog.Info("init jenkins success")
}
